package com.atguigu.flink.chapter05.transform;

import javafx.scene.chart.ValueAxis;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

public class FlatMapDemo {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port",2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);

        env.fromElements(23,24,25,65,78)
                .flatMap(new FlatMapFunction<Integer, Integer>() {
                    @Override
                    public void flatMap(Integer value, Collector<Integer> out) throws Exception {
                        /*out.collect(value * value);
                        out.collect(value * value * value);
                         */
                        if (value % 2 == 1){
                            out.collect(value);
                        }
                    }
                })
                .print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


//public class FlatMapDemo {
//    public static void main(String[] args) {
//        Configuration conf = new Configuration();
//        conf.setInteger("rest.port",2000);
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//        env.setParallelism(1);
//
//        env.fromElements(23,26,27,29,80)
//                .flatMap(new FlatMapFunction<Integer, Integer>() {
//                    @Override
//                    public void flatMap(Integer value, Collector<Integer> out) throws Exception {
////                        out.collect(value * value);
//////                        out.collect(value * value * value);
//                        if (value % 2 == 1){
//                            out.collect(value);
//                        }
//                    }
//                })
//                .print();
//        try {
//            env.execute();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}


//public class FlatMapDemo {
//    public static void main(String[] args) {
//        Configuration conf = new Configuration();
//        conf.setInteger("rest.port",2000);
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//        env.setParallelism(1);
//
//        env.fromElements(23,25,27,90)
//                .flatMap(new FlatMapFunction<Integer, Integer>() {
//                    @Override
//                    public void flatMap(Integer value, Collector<Integer> out) throws Exception {
//                        /*out.collect(value * value);
//                        out.collect(value * value * value);
//                         */
//                        if (value % 2 == 1){
//                            out.collect(value);
//                        }
//                    }
//                })
//                .print();
//
//        try {
//            env.execute();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}